package com.kongge.algorithm.demo;

import java.util.ArrayList;
import java.util.List;

import com.kongge.algorithm.tree.TreeNode;

/**
 * 请完成一个函数，输入一个二叉树，，该函数输出它的镜像。
 * @author gaoshiqi
 *
 */
public class TreeMirror implements IAlgorithm {

	public void execute() {
		TreeNode<Integer> root = TreeNode.createTree(new Integer[] {1, 2, 3, 4, 5, 6, 7, 8, 9});
		root = getTreeMirror(root);
		List<TreeNode<Integer>> resultList = new ArrayList<TreeNode<Integer>>();
		TreeNode.arrangementTraveseTree(root, resultList);
		TreeNode.printResult(resultList);
	}

	private TreeNode<Integer> getTreeMirror(TreeNode<Integer> root) {
		if (root == null) {
			return null;
		}
		TreeNode<Integer> temp = root.left;
		root.left = getTreeMirror(root.right);
		root.right = getTreeMirror(temp);
		return root;
	}
}
